package com.sultan.guante.userSystem.web;

import java.io.IOException;
import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sultan.guante.userSystem.domain.Users;
import com.sultan.guante.userSystem.service.UserService;

@ManagedBean
@SessionScoped
@Component
public class UserBean implements Serializable {

	
	@Autowired
	private UserService userService;
	
	private Users user = new Users();
	

	public UserService getUserService() {
		return userService;
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
		
	
	public String addUser()
	{
		
	    user.setEnabled(true);
		
		userService.save(user);

	return "";
	}
	
	public Users getUser() {
	
		return user;
	}
	public void setUser(Users user) {
		this.user = user;
	}
	public String editUser(Long userId) throws IOException {
	//	user = userService.get(new Long(userId));
		user = userService.get(userId);
		FacesContext.getCurrentInstance().getExternalContext().redirect("faces/userEdit.xhtml");
		return "";
	}
	
}
